package com.winsomely.leecode;

import java.util.HashMap;
import java.util.Map;

/**
 * 反转链表
 * 
 * @author liujiawei
 *
 */
public class ContainsNearbyDuplicate {

	public boolean containsNearbyDuplicate(int[] nums, int k) {
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < nums.length; i++) {
			if (map.containsKey(nums[i])) {
				if (Math.abs(map.get(nums[i]) - i) <= k) {
					return true;
				}
			}
			map.put(nums[i], i);
		}
		return false;
	}

	public static void main(String[] args) {
		ContainsNearbyDuplicate t = new ContainsNearbyDuplicate();
		int[] nums = { 1, 0, 1, 1 };
		int k = 1;
		System.out.println(t.containsNearbyDuplicate(nums, k));
	}

}
